<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
	<form class="layui-form layui-form-pane">
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>媒体名称</label>
			<div class="layui-input-block">
				<input type="text" name="mp_name" required lay-verify="required" placeholder="请输入媒体名称" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux">小程序的名称</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>公司名称</label>
			<div class="layui-input-block">
				<input type="text" name="com_name" required lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux">小程序的所属</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">类型</label>
			<div class="layui-input-block">
				<select name="type" lay-filter="type">
					<option disabled selected value="请选择类型">请选择类型</option>
					<option value="1">订阅号appid</option>
					<option value="2">服务号appid</option>
					<option value="3">APP</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item dy">
			<div class="layui-inline">
				<label class="layui-form-label">订阅号appid</label>
				<div class="layui-input-block">
					<input type="text" name="dy_appid" placeholder="请输入订阅号appid" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">订阅号秘钥</label>
				<div class="layui-input-block">
					<input type="text" name="dy_secret" placeholder="请输入订阅号秘钥" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item fw">
			<div class="layui-inline">
				<label class="layui-form-label">服务号appid</label>
				<div class="layui-input-block">
					<input type="text" name="fw_appid" placeholder="请输入服务号appid" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">服务号秘钥</label>
				<div class="layui-input-block">
					<input type="text" name="fw_secret" placeholder="请输入服务号秘钥" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item app">
			<div class="layui-inline">
				<label class="layui-form-label">APP秘钥</label>
				<div class="layui-input-block">
					<input type="text" name="app_secret" placeholder="请输入APP秘钥" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input class="layui-btn" lay-submit lay-filter="form" value="立即提交" readonly>
			</div>
		</div>
	</form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
	layui.use(['element', 'table','jquery','form','layer'], function(){
		let $ = layui.jquery
			,element = layui.element
			,layer = layui.layer
			,form = layui.form;
		$(".dy").hide();
		$(".fw").hide();
		$(".app").hide();
		form.on('select(type)', function(data){
			if(data.value == '1') {
				$(".dy").show();
				$(".fw").hide();
				$(".app").hide();
			}else if(data.value == '2') {
				$(".dy").hide();
				$(".fw").show();
				$(".app").hide();
			}else if(data.value == '3'){
				$(".dy").hide();
				$(".fw").hide();
				$(".app").show();
			}
			form.render('select');
		});

		//监听提交
		form.on('submit(form)', function (data) {
			let field = data.field;
			let isLoad;
			$.ajax({
				url: '{:url("Mp/add")}',
				method: "post",
				data: field,
				beforeSend: function () {
					isLoad = layer.load(0, {
						shade: false
					}); //0代表加载的风格，支持0-2
				},
				success: function (result) {
					layer.msg(result.msg);
					if (result.code === 1) {
						setTimeout(function () {
							let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭
							parent.location.reload();
						}, 2000);
					}
				},
				complete: function () {
					layer.close(isLoad)
				},
				error: function (error) {
					console.log(error)
				}
			});
			return false;
		});
	});

</script>